/**
 * 诊断工具函数
 * 提供语法检查和错误诊断相关功能
 */
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver/node'
import { TextDocument } from 'vscode-languageserver-textdocument'

/**
 * 创建诊断信息的工具函数
 * @param document 文档对象
 * @param severity 诊断严重程度
 * @param range 诊断范围
 * @param message 诊断消息
 * @returns 诊断对象
 */
export const createDiagnostic = (
	document: TextDocument,
	severity: DiagnosticSeverity,
	range: { start: { line: number; character: number }; end: { line: number; character: number } },
	message: string
): Diagnostic => ({
	severity,
	range,
	message,
	source: '4GL Helper',
	relatedInformation: [{
		location: { uri: document.uri, range: { ...range } },
		message
	}]
})

/**
 * 预编译正则表达式以提升性能
 */
export const REGEX_PATTERNS = {
	COMMENT: /^[#\s]/,  // 匹配注释行
	STRING: /["'].+['"]/,  // 匹配字符串
	LOWERCASE_WORD: /\b[a-z]{2,}\b/g  // 匹配小写单词
}